<template>
  <div class="layout-container test-sample-selected">
    <FlowStep :activeStep="1" />
    <div class="search common-buttons">
      <el-input
        v-model="keyword"
        style="width: 320px"
        placeholder="请搜索"
        clearable
      ></el-input>
      <el-button type="primary" :icon="Search" @click="onQuery({ pageNo: 1 })"
        >查找</el-button
      >
    </div>

    <div class="layout-container-table">
      <CommonTable
        :data="state.tableData"
        v-model:page="page"
        :total="total"
        v-loading="loading"
        highlight-current-row
        :showSelection="false"
        @onQuery="onQuery"
        @current-change="handleCurrentChange"
      >
        <el-table-column prop="sampleName" label="试验样本名称" />
        <el-table-column prop="dytStyle" label="导引头体制" />
        <el-table-column prop="interType" label="干扰类型" />
        <el-table-column prop="interScenType" label="干扰场景类型" />
        <el-table-column prop="foreignElectEquip" label="外军电子战装备类型" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column prop="studen" label="评估状态" width="160">
          <!--   0-原始样本
                  1-完成数据处理
                  2-完成静态相似性评估
                  3-完成动态相似性评估
                  4-完成性能推算
                  5-完成边界推算 -->
          <template #default="scope">
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '1'"
            >
              <div class="round" style="background: rgba(22, 168, 49, 1)"></div>
              <span style="color: rgba(22, 168, 49, 1)">未评估</span>
            </div>
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '2'"
            >
              <div class="round" style="background: #ff69ab"></div>
              <span style="color: #ff69ab">完成静态相似性评估</span>
            </div>
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '3'"
            >
              <div class="round" style="background: #fe8b42"></div>
              <span style="color: #fe8b42">完成动态相似性评估</span>
            </div>
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '4'"
            >
              <div class="round" style="background: #ff00ff"></div>
              <span style="color: #ff00ff">完成性能推算</span>
            </div>
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '5'"
            >
              <div class="round" style="background: #8000ff"></div>
              <span style="color: #8000ff">完成边界推算</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="60">
          <template #default="scope">
            <el-button
              link
              type="primary"
              size="small"
              :disabled="!(scope.row.evaluationStage === '3')"
              @click="onLook(scope.$index, scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </CommonTable>
    </div>

    <div class="step-buttons common-buttons">
      <el-button type="primary" @click="onStep">下一步</el-button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from "vue";
import { Search } from "@element-plus/icons-vue";
import { ElMessage, FormInstance, ElMessageBox, ElTable } from "element-plus";
import { useRoute, useRouter } from "vue-router";
import CommonTable from "@/components/common-table/index.vue";
import { Page } from "@/components/common-table/type";
import { httpSampleDataList } from "@/api/similarityEvaluationSystem";
import { reverseContentType } from "@/utils/tools";
import FlowStep from "../FlowStep/index.vue";

let $router = useRouter();
const keyword = ref<string>("");
const state = reactive<any>({
  tableData: [],
});
const loading = ref<boolean>(false);
const page = reactive<Page>({
  current: 1,
  pageSize: 20,
});
const total = ref<number>(0);
// 当前行
const currentRow = ref({});
const singleTableRef = ref<InstanceType<typeof ElTable>>();

onMounted(() => {
  onQuery({ pageNo: 1 });
});

// 查询数据
const onQuery = (val: any) => {
  const params = {
    sampleName: keyword.value,
    sampleType: "1", // 0-原始样本，1-处理后样本
    sampleId: "",
    evaluationStage: "1",
    pageSize: page.pageSize,
    pageNo: page.current,
    ...val,
  };
  loading.value = true;
  httpSampleDataList(params).then((res) => {
    const result = res.data;
    loading.value = false;
    const { rows, totalRows } = result;
    total.value = totalRows;
    state.tableData = rows;
    currentRow.value = {};
  });
};

// 过滤出keys
const filterKeys = (arr: []) => {
  let keys: string[] = [];
  for (let item of arr) {
    keys.push(item.id);
  }
  return keys;
};

// 查看结果
const onLook = (index: number, row: unknown) => {
  $router.push({
    path: "/similarityEvaluateSystem/resultVisualDisplay",
    query: {
      layerType: "look",
      dealSampleId: row.id,
      sampleName: row.sampleName,
    },
  });
};

// 下一步
const onStep = () => {
  if (!currentRow.value.id) {
    ElMessage({
      message: "请选择一条试验样本数据!",
      type: "warning",
    });
    return;
  }

  $router.push({
    path: "/similarityEvaluateSystem/siftInfoParam",
    query: {
      dealSampleId: currentRow?.value.id,
      sampleName: currentRow?.value.sampleName,
    },
  });
};

// 选中当前行
const handleCurrentChange = (val: Object | undefined) => {
  currentRow.value = val;
};
</script>

<style lang="scss" scoped>
@import "@/assets/style/buttons";
.test-sample-selected {
  .search {
    display: flex;
    padding: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    :deep() {
      .el-input--small .el-input__wrapper {
        margin-right: 10px;
      }
    }
  }
  .layout-container-table {
    .el-button--small {
      background: transparent;
      // color: rgba(24, 81, 237, 1);
      font-size: 13px;
    }
  }

  .evaluation-process {
    display: flex;
    cursor: pointer;
    // color: rgb(24, 81, 237);
    .round {
      display: inline-block;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      position: relative;
      top: 7px;
      right: 4px;
    }
  }

  .step-buttons {
    display: flex;
    justify-content: center;
    box-shadow: 0px 0px 10px rgba(218, 222, 224, 1);
    padding: 10px 0;
  }
}
</style>
